﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PMPUtils.Goals;
using PMPUtils.Form;

namespace PMP.Goals
{
    public partial class GoalDetailManagement_SwitchOwner : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormUtil.Authenticate(Session, Response);

            if (!IsPostBack)
            {
                txtGoalDetail.Text = Request.Params["GOALDETAIL"];
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            String goalDetailID = txtGoalDetail.Text.Trim();
            String newOwner = ddlUsers.SelectedValue.Trim();

            if (newOwner.Equals(String.Empty))
            {
                Messenger.Show(Response, "Please select the new owner.");
                return;
            }

            try
            {
                GoalDetailsOperator.SwitchOwner(goalDetailID, newOwner);
            }
            catch (Exception ex)
            {
                Messenger.Show(Response, "Error: " + ex.Message);
                return;
            }

            Messenger.Show(Response, "Update Successfully.");
            Close();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Close()
        {
            PopupForm switchUser = new PopupForm(Response);
            switchUser.Close();
        }
    }
}
